<template>
  <div class="announcement-detail-container">
    <van-nav-bar
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <h1 class="announcement-title">{{ announcement.title }}</h1>
    <p class="announcement-date">{{ announcement.date }}</p>
    <div class="announcement-content">
<!--      <p v-for="line in announcement.content.split('\n')" :key="line">{{ line }}</p>-->
      <p v-for="(line, index) in announcement.content.split('').reduce((acc, char, i) => {
      if (i % 23 === 0 && i!== 0) {
        acc.push('');
      }
      const lastIndex = acc.length - 1;
      acc[lastIndex] += char;
      return acc;
    }, [''])" :key="index">{{ line }}</p>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: 'AnnouncementOne',
  data() {
    return {
      announcement: {},
      id: ''
    }
    },
  created() {
    this.id=this.$route.params.id
    this.findOne()

  },
  methods: {
    findOne() {
      // 根据id查找公告
      axios.get('announcement/findOne?id='+this.id).then(res => {
        console.log(res)
        this.announcement = res.data
      })
    },
    onClickLeft() {
      this.$router.push({path: '/AnnouncementList'})
    },
  }

}
</script>
<style>
</style>
